package Thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-01-29
 * Time: 17:00
 */
public class Thread13 {
    public static void main(String[] args) throws InterruptedException {
        func1();
        func2();
    }

    private static void func2() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            long a = 0;
            for (long i = 0; i < 100_0000_0000L ; i++) {
                a++;
            }
        });
        Thread t2 = new Thread(() ->{
            long b = 0;
            for (long i = 0; i < 100_0000_0000L ; i++) {
                b++;
            }
        });
        long beg = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long end = System.currentTimeMillis();
        System.out.println("并发执行时间: "+(end - beg)+"ms");
    }

    private static void func1() {
        long start = System.currentTimeMillis();
        long a = 0;
        for (long i = 0; i < 100_0000_0000L ; i++) {
            a++;
        }
        long b = 0;
        for (long i = 0; i < 100_0000_0000L ; i++) {
            b++;
        }
        long end = System.currentTimeMillis();
        System.out.println("执行时间: "+(end - start)+"ms");
    }
}
